|
PrintDialogで設定した内容を利用し、自作のプログラムに利用するため作ったプログラムで、単に設定した内容を表示するだけです。
下図の左はプリンタ−の設定を、下図の右は で設定した時のpdl(オブジェクト変数)を選択し右クリックで出てくる「クイック ウオッチ」で表示したもので、この内容の一部をプログラムで読み出し textBoxに書き出したものです。 |
|
|
![]() |
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace printerinfo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) // プリンタ−設定ボタン
{
PrintDialog pdl = new PrintDialog(); //pdl オブジェクト、インスタンス変数
pdl.ShowDialog();
textBox1.Clear();
// プリンタ名の取得
string defaultPrinterName = pdl.PrinterSettings.PrinterName;
textBox1.AppendText("通常使うプリンタは" + defaultPrinterName + "です。\r\n");
string paper = pdl.PrinterSettings.DefaultPageSettings.PaperSize.PaperName;
textBox1.AppendText("PaperName= " + paper + "\r\n\r\n");
int h = pdl.PrinterSettings.DefaultPageSettings.Bounds.Height;
textBox1.AppendText("Heigth= " + h + "\r\n");
int w = pdl.PrinterSettings.DefaultPageSettings.Bounds.Width;
textBox1.AppendText("Width= " + w + "\r\n\r\n");
float mx = pdl.PrinterSettings.DefaultPageSettings.HardMarginX;
textBox1.AppendText("MarginX= " + mx + "\r\n");
float my = pdl.PrinterSettings.DefaultPageSettings.HardMarginY;
textBox1.AppendText("MarginY= " + my + "\r\n\r\n");
float dpix = pdl.PrinterSettings.DefaultPageSettings.PrinterResolution.X;
textBox1.AppendText("DpiX= " + dpix + "\r\n");
float dpiy = pdl.PrinterSettings.DefaultPageSettings.PrinterResolution.X;
textBox1.AppendText("DpiY= " + dpiy + "\r\n");
}
private void button2_Click(object sender, EventArgs e)
{
Close();
}
}
}
|
|